# Maintainer: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: mutantmonkey <mutantmonkey@gmail.com>

pkgname=libmilter
_pkgname=sendmail
pkgver=8.15.2
pkgrel=2
pkgdesc='Implementation of the sendmail Mail Filter API'
url='https://www.proofpoint.com/us/sendmail-open-source'
arch=('x86_64')
options=('staticlibs')
license=('custom:Sendmail open source license')
validpgpkeys=('30BCA74705FA415455731D7BAAF5B5DE05BDCC53')
source=("http://ftp.sendmail.org/${_pkgname}.${pkgver}.tar.gz"{,.sig}
        'fd-passing-libmilter.patch')
sha256sums=('24f94b5fd76705f15897a78932a5f2439a32b1a2fdc35769bb1a5f5d9b4db439'
            'SKIP'
            'b856ebc17e39151652bda93f40f79756ac83eb4a0b67e6d55c049f3ebde42983')

prepare() {
	cd "${srcdir}/${_pkgname}-${pkgver}"
	patch -p1 -i ../fd-passing-libmilter.patch # FS#49421

	# From http://www.j-chkmail.org/wiki/doku.php/doc/installation/start#libmilter
	cat >> devtools/Site/site.config.m4 <<EOF
dnl Include our flags
APPENDDEF(\`conf_libmilter_ENVDEF',\`${CPPFLAGS} ${CFLAGS}')
dnl Enable libmilter with a pool of workers
APPENDDEF(\`conf_libmilter_ENVDEF',\`-D_FFR_WORKERS_POOL=1 -DMIN_WORKERS=4')
dnl Use poll instead of select
APPENDDEF(\`conf_libmilter_ENVDEF',\`-DSM_CONF_POLL=1')
dnl Enable IPv6
APPENDDEF(\`conf_libmilter_ENVDEF',\`-DNETINET6=1')
dnl Add -fPIC
APPENDDEF(\`conf_libmilter_ENVDEF',\`-fPIC')
EOF
}

build() {
	cd "${srcdir}/${_pkgname}-${pkgver}/${pkgname}"
	./Build
}

package() {
	cd "${srcdir}/${_pkgname}-${pkgver}/${pkgname}"
	install -d "${pkgdir}/usr/lib"
	./Build DESTDIR="${pkgdir}" install
	install -Dm644 ../LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
	chown -R root:root "${pkgdir}"
}
